package com.blb.community.service.impl;

import com.aliyun.dysmsapi20170525.models.SendSmsRequest;
import com.aliyun.dysmsapi20170525.models.SendSmsResponse;
import com.aliyun.tea.TeaException;
import com.aliyun.teaopenapi.models.Config;
import com.aliyun.teautil.models.RuntimeOptions;
import com.blb.community.service.IMSService;
import org.springframework.stereotype.Service;

import java.util.Random;

/**
 * @Author 帅帅
 * @Date 2022/7/18 16:25
 * @PackageName:com.blb.community.service.impl
 * @ClassName: IMSServiceImpl
 * @Description: TODO
 * @Version 1.0
 */
@Service
public class IMSServiceImpl implements IMSService {

    @Override
    public Integer getCode() throws Exception {
        int i = new Random().nextInt(10000 - 1000) + 1000 + 1;
        com.aliyun.dysmsapi20170525.Client client = new com.aliyun.dysmsapi20170525.Client(new Config()
                // 您的 AccessKey ID
                .setAccessKeyId("")
                // 您的 AccessKey Secret
                .setAccessKeySecret(""));
        SendSmsRequest sendSmsRequest = new SendSmsRequest()
                .setSignName("阿里云短信测试")
                .setTemplateCode("")
                .setPhoneNumbers("")
                .setTemplateParam("{code:" + i + "}");
        RuntimeOptions runtime = new RuntimeOptions();
        Integer statusCode = null;
        try {
            // 复制代码运行请自行打印 API 的返回值
            SendSmsResponse sendSmsResponse = client.sendSmsWithOptions(sendSmsRequest, runtime);
            statusCode = sendSmsResponse.getStatusCode();
            return statusCode;
        } catch (TeaException error) {
            // 如有需要，请打印 error
            com.aliyun.teautil.Common.assertAsString(error.message);
        } catch (Exception _error) {
            TeaException error = new TeaException(_error.getMessage(), _error);
            // 如有需要，请打印 error
            com.aliyun.teautil.Common.assertAsString(error.message);
        }
        return statusCode;
    }
}
